package org.ns.summer.beans.beanprocessor;

import org.ns.summer.beans.ApplicationContext;
import org.ns.summer.beans.ConfigurableBeanFactory;
import org.ns.summer.beans.InitializingBeanPostProcessor;

public class ApplicationContextAwareProcessor implements InitializingBeanPostProcessor {
    private ApplicationContext applicationContext;

    public ApplicationContextAwareProcessor(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
    @Override
    public void preHandler(ConfigurableBeanFactory beanFactory, Object bean, String beanName) {
        if (bean instanceof ApplicationContextAware) {
            ((ApplicationContextAware)bean).setApplicationContext(applicationContext);
        }
    }
}
